﻿using AutoMapper;
using MediatR;
using S.BreedingHistory.Domain.Model;
using S.BreedingHistory.Infrastructure.Interface;
using S.BreedingHistory.Read.Api.Application.Command;
using S.BreedingHistory.Read.Api.Dto;

namespace S.BreedingHistory.Read.Api.Application.CommandHandler
{
    public class BreedingHistoryByPIdCommandHandler : IRequestHandler<BreedingHistoryByPIdCommand, BreedingHistoryListDto>
    {
        private readonly IBreedingHistoryRepository breedingHistoryRepository;
        private readonly IMapper mapper;

        public BreedingHistoryByPIdCommandHandler(IBreedingHistoryRepository breedingHistoryRepository,IMapper mapper)
        {
            this.breedingHistoryRepository = breedingHistoryRepository;
            this.mapper = mapper;
        }
        public async Task<BreedingHistoryListDto> Handle(BreedingHistoryByPIdCommand request, CancellationToken cancellationToken)
        {
            BreedingHistoryModel breeding = await breedingHistoryRepository.GetBreedingHistoryModelById(request.bhrId);
            BreedingHistoryListDto breedHistoryPageListDto = mapper.Map<BreedingHistoryListDto>(breeding);
            return breedHistoryPageListDto;
        }
    }
}
